package com.wzh.service;

import com.wzh.dao.UserZpDao;
import com.wzh.pojo.Po.UserZp;
import com.wzh.pojo.Resp.DataResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

	@Autowired
	private UserZpDao userZpDao;
	public DataResp<Object> login(UserZp userZp) {
		DataResp<Object> resp=new DataResp<>();
		UserZp user=userZpDao.login(userZp);
		if (user==null){
			resp.setCode(203);
			resp.setMes("账号或密码错误！");
		}else{
			resp.setData(user);
			resp.setMes("登录成功！");
		}
		return resp;
	}

	public DataResp<Object> register(UserZp userZp) {
		DataResp<Object> resp=new DataResp<>();

		UserZp user=userZpDao.findPhone(userZp);//查询用户是否存

		if (user==null){
			//手机号不存在允许注册
			int code=userZpDao.register(userZp);
			if (code>0){
				//注册成功
				resp.setData(userZp);
				resp.setMes("注册成功！");
			}else{
				resp.setCode(205);
				resp.setMes("注册失败！");
			}


		}else{
			resp.setCode(204);
			resp.setMes("手机号已注册！");
		}
		return resp;
	}
}
